<?php
declare(strict_types=1);
namespace app\common\service\ReportService;

use app\model\BbcModel\Country;
use app\model\BbcModel\SearchLog;
use app\Normal;

class SearchLogService
{

    public function searchWordList($param){
        if(empty($param['cid'])){
            return Normal::returnCode(Normal::FAIL,'缺少参数cid');
        }
        $limit=$param['limit']??10;
        $page=$param['page']??1;
        $where=[
            ['cid','=',$param['cid']],
            '_groupBy_'=>'word',
            '_fields_'=>'id,word,count(*) as num',
            '_order_'=>'num desc'
        ];
        if(!empty($param['key_word'])){
            $where[]=['word','like','%'.$param['key_word'].'%'];
        }
        $data['list'] = SearchLog::instance()->listPages($where,$limit,$page);
        $data['total'] = SearchLog::instance()->countNum($where);
        return Normal::returnCode(Normal::SUC,'请求成功',$data);
    }

}